#!/usr/bin/env/python
# -*- coding: utf-8 -*- 

# @File : Server.py 
# @Author : t_fengyun
# @Time : 2019/9/9 16:37 
# @desc : there is description 

import socket,os

server = socket.socket()
ip_port = ('localhost',1234)

server.bind(ip_port)
server.listen(5)

while True:
    print('waiting on connection')
    conn,addr = server.accept()
    print('connected by',addr)

    while True:
        data = conn.recv(1024).decode()
        if not data:
            print('client is lost...')
            break

        print('data :' ,data)
        res = os.popen(data).read()
        print('command:',res)

        conn.sendall(res.encode())
    '''关闭句柄,在一条消息发送完成再关闭'''
    conn.close()
server.close()
